package leecode

func findLength(nums1 []int, nums2 []int) int {
	var result int
	dp := make([][]int, len(nums2)+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, len(nums1)+1)
	}
	for i := 1; i < len(dp); i++ {
		for j := 1; j < len(dp[i]); j++ {
			if nums1[j-1] == nums2[i-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			}
			result = max(result, dp[i][j])
		}
	}
	return result
}
